package cn.wolfcode.wolf2w.redis.util;

import cn.wolfcode.wolf2w.util.Consts;
import lombok.Getter;
import lombok.Setter;

@Getter
public enum RedisKeys {
    //实例
    //今日访问的key
    VISIT_TOTAL("visit_total",-1L),
    VISIT_TODAY("visit_today",-1L),
    //顶的标记key
    STRATEGY_THUMA("strategy_thuma",-1L),
    //用户攻略数组的实例key
    USER_STRATEGY_FAVOR("user_strategy_favor",-1L),
    //攻略统计VO的key对象实例
    STRATEGY_STATIS_VO("strategy_statis_vo", -1l),  //约定-1表示不设定超时
    VERIFY_CODE("verify_code", Consts.VERIFY_CODE_VAI_TIME*60l),
    USER_LOGIN("user_login",Consts.USER_INFO_TOKEN_VAI_TIME*60l);


    //两个字段:前缀和有效时间
    private String prefix;
    private Long timeout;

    public void setPrefix(String prefix){
        this.prefix=prefix;
    }
    //构造器,给这两个字段赋值
    RedisKeys(String prefix,Long timeout){
        this.prefix=prefix;
        this.timeout=timeout;
    }

    //方法,生成key
    public String join(String... values){
        StringBuilder sb = new StringBuilder(80);
        sb.append(this.prefix);
        for (String value : values) {
            sb.append(":"+value);
        }
        return sb.toString();
    }

}
